package com.stylefeng.guns.modular.system.controller;

import com.stylefeng.guns.core.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.stylefeng.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.stylefeng.guns.modular.system.model.CarouselAdvertisement;
import com.stylefeng.guns.modular.system.service.ICarouselAdvertisementService;

/**
 * 轮播图管理控制器
 *
 * @author fengshuonan
 * @Date 2019-09-01 15:26:13
 */
@Controller
@RequestMapping("/carouselAdvertisement")
public class CarouselAdvertisementController extends BaseController {

    private String PREFIX = "/system/carouselAdvertisement/";

    @Autowired
    private ICarouselAdvertisementService carouselAdvertisementService;

    /**
     * 跳转到轮播图管理首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "carouselAdvertisement.html";
    }

    /**
     * 跳转到添加轮播图管理
     */
    @RequestMapping("/carouselAdvertisement_add")
    public String carouselAdvertisementAdd() {
        return PREFIX + "carouselAdvertisement_add.html";
    }

    /**
     * 跳转到修改轮播图管理
     */
    @RequestMapping("/carouselAdvertisement_update/{carouselAdvertisementId}")
    public String carouselAdvertisementUpdate(@PathVariable Integer carouselAdvertisementId, Model model) {
        CarouselAdvertisement carouselAdvertisement = carouselAdvertisementService.selectById(carouselAdvertisementId);
        model.addAttribute("item",carouselAdvertisement);
        LogObjectHolder.me().set(carouselAdvertisement);
        return PREFIX + "carouselAdvertisement_edit.html";
    }

    /**
     * 获取轮播图管理列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return carouselAdvertisementService.selectList(null);
    }

    /**
     * 新增轮播图管理
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(CarouselAdvertisement carouselAdvertisement) {
        carouselAdvertisementService.insert(carouselAdvertisement);
        return SUCCESS_TIP;
    }

    /**
     * 删除轮播图管理
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer carouselAdvertisementId) {
        carouselAdvertisementService.deleteById(carouselAdvertisementId);
        return SUCCESS_TIP;
    }

    /**
     * 修改轮播图管理
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(CarouselAdvertisement carouselAdvertisement) {
        carouselAdvertisementService.updateById(carouselAdvertisement);
        return SUCCESS_TIP;
    }

    /**
     * 轮播图管理详情
     */
    @RequestMapping(value = "/detail/{carouselAdvertisementId}")
    @ResponseBody
    public Object detail(@PathVariable("carouselAdvertisementId") Integer carouselAdvertisementId) {
        return carouselAdvertisementService.selectById(carouselAdvertisementId);
    }
}
